UIViewControllerRepresentable
SwiftUI MIDI Bluetooth example
Content View:
@State private var btScan = false
@State private var btAdvertise = false
var body: some View {
VStack {
Button("Bluetooth MIDI Scan") { self.btScan = true }
.sheet(isPresented: $btScan) { BTConnectController(btScan: self.$btScan) }
Button("Bluetooth Advertise") { self.btAdvertise = true }
.sheet(isPresented: $btAdvertise) { BTPeripheralController(btAdvertise: self.$btAdvertise) }
}
.padding()
}
struct BTConnectController : UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> CABTMIDICentralViewController {
CABTMIDICentralViewController()
}
func updateUIViewController(_ uiViewController: CABTMIDICentralViewController, context: Context) {
}
typealias UIViewControllerType = CABTMIDICentralViewController
@Binding var btScan: Bool
}
struct BTPeripheralController : UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> CABTMIDILocalPeripheralViewController {
CABTMIDILocalPeripheralViewController()
}
func updateUIViewController(_ uiViewController: CABTMIDILocalPeripheralViewController, context: Context) {
}
typealias UIViewControllerType = CABTMIDILocalPeripheralViewController
@Binding var btAdvertise: Bool
}
Hope it helps, @JSE98
Best regards
Andreas
Post
Replies
Boosts
Views
Activity
Hi,
I struggled forever with this too, but for me the app’s Icloud Drive folder suddenly became visible to Finder after I did this:
XCode:
Product -> Clean Build Folder
Build For -> Running
Show build location in finder
Copied my app bundle from XCode’s build folder to the /Applications folder and executed the app from there. Popped up in Finder immidiately. Who knew.
Maybe it does not work. Then how to quit Share Extension after its operation finished?
The "returningItems" parameters are referring to the output object(s), including any changes written to it. If this doesn't apply to your extension and you want to exit cleanly, just return "nil":
self.extensionContext!.completeRequest(returningItems: nil, completionHandler: nil)
Andreas